/* eslint-disable no-empty-pattern */
import { api_add, api_delById, api_modifyAll, api_queryById, api_listAll } from '@/api/crud'
import { api_patchEnabled, api_checkLabel, api_checkCode } from '@/api/sys_role'

const pathName = 'role'

const state = {
  allRole: [],
}

const mutations = {}

const actions = {
  // 添加角色
  add({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_add(pathName, paramsJson)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 删除角色
  delById({}, id) {
    return new Promise((resolve, reject) => {
      api_delById(pathName, id)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 修改角色
  modifyAll({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_modifyAll(pathName, paramsJson)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 修改角色启用状态
  patchEnabled({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_patchEnabled(paramsJson)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 根据id查询到一个对象全部资料
  queryById({}, id) {
    return new Promise((resolve, reject) => {
      api_queryById(pathName, id)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 得到所有角色的列表
  listAll({}) {
    return new Promise((resolve, reject) => {
      api_listAll(pathName)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 验证角色名称是否已使用
  checkLabel({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_checkLabel(paramsJson)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 验证角色代码是否已使用
  checkCode({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_checkCode(paramsJson)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
